/*
 * @Author: liyongxuan
 * @Date: 2018-1-10 10:37:42
 * @description：协议核心条款清单组件
 */
<template>
    <div class="ca-box ca-m-t-20 ca-p-20 ca-m-b-20">
      <div class="ca-title">
        <el-button v-if="indexOrEdit" type="text" class="ca-edit-btn el-icon-edit ca-m-r-10 right-fs-30" @click="indexOrEdit = false">编辑</el-button>
        <el-button v-if="!indexOrEdit" size="medium" @click="closeEdit()" class="right-fs-30">取消</el-button>
        <el-button v-if="!indexOrEdit" type="primary" size="medium" @click="save" class="right-fs-30 margin20">保存</el-button>
        <h3 class="ca-m-b-20">协议核心条款清单</h3>
        <el-form ref="dataForm">
            <table class="ca-table ca-m-t-20 line-height-td">
                <tr class="height-line">
                    <th width="25%">审查要点</th>
                    <th width="25%">方案内容</th>
                    <th width="25%">合法合规性判断</th>
                    <th width="25%">是否可调整</th>
                </tr>
                <tr v-for="(item,index) in list" :key="index" v-if="indexOrEdit">
                    <td>{{item.oneCol}}</td>
                    <td>{{item.nameOfBank}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.accountNumber}}</td>
                </tr>
                <tr v-for="(item,index) in list" :key="index" v-if="!indexOrEdit">
                    <td>{{item.oneCol}}</td>
                    <td>
                        <el-input v-model="item.nameOfBank" type="text"></el-input>                        
                    </td>
                    <td>
                        <el-input v-model="item.name" type="text"></el-input>                        
                    </td>
                    <td>
                        <el-input v-model="item.accountNumber" type="text"></el-input>                        
                    </td>
                </tr>
            </table>
        </el-form>
      </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import { api } from '../../../api';
    import { apiHttp, STATUS_HTTP_SUCCESS } from '__service/csHttp';
    import { isNoAuth,addRemind } from '__service/utils';
    
    export default {
        data() {
            return {
                list: [
                    {oneCol: '基金组织形式为公司制或有限合伙制',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '1'},
                    {oneCol: '基金规模1亿元以上',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '2'},
                    {oneCol: '基金投资领域：先进制造、大健康、互联网、新材料、节能环保等新兴产业领域',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '3'},
                    {oneCol: '基金存续期原则上不超过7年',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '4'},
                    {oneCol: '所有出资人以货币形式出资',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '5'},
                    {oneCol: '基金托管：有资质的银行',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '6'},
                    {oneCol: '管理团队有3名具备3年以上投资或相关工作经验的专职人员',accountNumber: '', fundId: this.itemId,id: '',name: '',nameOfBank: '',type: '7'},
                ],
              indexOrEdit: true,
              resultDataList: []//
            }
        },
        watch: {
        },
        props: ['itemId'],
        mounted() {
            isNoAuth()
            this.getList()
        },
        methods: {
            // 获取协议核心条款清单
            async getList() {
                const {resCode,data} = await apiHttp(api.GET_FUND_ACCOUNTS,{id: this.itemId})
                if (resCode === STATUS_HTTP_SUCCESS) {
                    this.resultDataList = data
                    if (data.length > 0) {
                        data.map(u => {
                            this.list[u.type - 1].accountNumber = u.accountNumber
                            this.list[u.type - 1].nameOfBank = u.nameOfBank
                            this.list[u.type - 1].name = u.name
                            this.list[u.type - 1].id = u.id
                            this.list[u.type - 1].fundId = u.fundId
                        })
                    }
                }
            },
            // 关闭编辑页
            closeEdit() {
                this.indexOrEdit = true
            },
            // 修改
            async save() {
                let query = []
                this.list.map(u => {
                    query.push({
                        accountNumber: u.accountNumber,
                        fundId: u.fundId,
                        nameOfBank: u.nameOfBank,
                        id: u.id,
                        name: u.name,
                        type: u.type,
                    })
                })
                let apiName = ''
                if (this.resultDataList.length === 0) {
                    apiName = 'ADD_FUND_ACCOUNT'
                } else {
                    apiName = 'PUT_FUND_ACCOUNT'
                }
                const {resCode} = await apiHttp(api[apiName],query)
                if (resCode === STATUS_HTTP_SUCCESS) {
                    this.$message({type: 'success',message: '成功'})
                    this.getList()
                    // 添加小红点
                    await addRemind({
                        dataId: this.itemId || '', // 业务id
                        dataTab: 1, // tab页顺序 head 也为0
                        dataType: 4, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                    });
                    // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                    this.$root.Dot.$emit('getDotList');
                    this.indexOrEdit = true
                }
            }
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.right-fs-30{
   float:right;
}
.height-line{
    line-height: 30px
}
.line-height-td td{
    line-height: 24px;
    vertical-align: middle;
}
.margin20{
    margin-right: 20px;
}
</style>
